import $ from 'jquery'
import { Toast, MessageBox, Indicator } from 'mint-ui'
function startLoading() {
  Indicator.open()
}
function endLoading() {
  Indicator.close()
}
let api = 'http://xhf.8jieyun.com'

export default {
  api,
  Tooast(msg) {
    Toast({
      message: msg,
      duration: 1000
    })
  },
  Tip(title, message) {
    MessageBox(title, message)
  },
  alert(msg, func) {
    MessageBox.alert(msg).then(action => {
      func()
    })
  },
  confirm(message, func) {
    MessageBox.confirm(message).then(action => {
      func()
    })
  },
  requset(url, type, data, func) {
    $.ajax({
      type: type,
      url: api + url,
      data: data,
      dataType: 'json',
      success: function(res) {
        if (res.code === 10200 || res.code === 10302) {
          func(res)
        } else {
          Toast({
            message: res.msg,
            duration: 1000
          })
        }
      }
    })
    setTimeout(function(){ endLoading() }, 300);
  }
}
